<?php
class My_member extends CI_Controller {
	public function __construct() {
		parent::__construct ();
		// 登录校验
		$this->common->check_login_mobile ();
		// 通过user_model的get_user_info_id方法获取个人信息
		$this->user_info = $this->user->get_user_info_id ( $_SESSION ['mobile'] ['id'] );
		$this->load->helper ( array (
				'form',
				'url' 
		) );
	}
	
	/**
	 * 我的会员
	 */
	public function index() {
		$data ['left'] = $this->load->view ( 'mobile/left', '', TRUE );
		
		$data ['foot'] = $this->load->view ( 'mobile/foot', '', TRUE );
		
		$data ['member_list'] = $this->get_member_list ( $this->user_info ['user_account'] ); // $member_lsit;
        $user = $this->user->get_user_info_id($_SESSION['user']['id']);
        $data['dqjb'] = $user['team_lv'];
		$this->load->view ( 'mobile/my_member', $data, FALSE );
	}
	
	/**
	 * 返回数据
	 */
	public function ajax_get_member_list() {
		$acc = $_POST ['acc'];
		
		if (! $acc) {
			echo 0;
			exit ();
		}
		$a = $this->get_member_list ( $acc );
		// echo json_encode($a);exit;
		header ( 'Content-Type:application/json; charset=utf-8' );
		
		exit ( json_encode ( $a ) );
	}
	
	/**
	 * 获取用户列表
	 */
	private function get_member_list($acc) {
		$member_lsit = $this->user->get_member_list_up ( $acc );
		
		$lv = array (
				'1' => '得道者',
				'2' => '天时',
				'3' => '地利',
				'4' => '人和',
				'5' => '君子' 
		);
		
		foreach ( $member_lsit as $k => $v ) {
			$num = count ( $this->user->get_member_list_up ( $v ['user_account'] ) );
			
			$member_lsit [$k] ['tj_num'] = $num;
			$member_lsit [$k] ['tlv'] = $lv [$v ['team_lv']];
		}
		
		return $member_lsit;
	}
}